package mapx

func CloneMap(a map[string]interface{}) (r map[string]interface{}) {
	if a == nil {
		return
	}
	r = map[string]interface{}{}
	for key, val := range a {
		r[key] = CloneAny(val)
	}

	return r
}

func CloneArray(a []interface{}) (r []interface{}) {
	r = make([]interface{}, len(a), cap(a))
	for i, val := range a {
		r[i] = CloneAny(val)
	}
	return
}

func CloneAny(a interface{}) (r interface{}) {
	switch v := a.(type) {
	case map[string]interface{}:
		r = CloneMap(v)
	case []interface{}:
		r = CloneArray(v)
	default:
		r = a
	}
	return
}
